package com.example.qxfw.backgroundManagement.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.qxfw.common.entity.CollectTime;
import com.example.qxfw.common.entity.PublishRecord;
import com.example.qxfw.rcyw.pojo.JobMake;
import org.apache.ibatis.annotations.*;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/3  星期一   10:32
 * @description : 此类用来 监控管理的底层数据交互
 ***************************************/
@Mapper
@DS("service")
public interface MonitoringManagementMapper {

    @Select("select distinct jobtype " +
            "from job_make")
    List<JobMake> selectJobType();

    @Select("select jobname, jobtype, maketimechar, maketimeinterval, makeshift, recentmaketime " +
            "from job_make")
    List<JobMake> selectAll();

    @Select("select recentmaketime " +
            "from job_make " +
            "where jobtype = #{jobType} and maketimechar like concat('%',#{makeTimeChar},'%') " +
            "order by recentmaketime desc " +
            "limit 1")
    List<JobMake> selectRecentMakeTime(@Param("jobType") String jobType, @Param("makeTimeChar") String makeTimeChar);

    @Select("select id, jobname, jobtype, nametype, maketimechar, maketimeinterval, makeshift, recentmaketime " +
            "from job_make " +
            "where jobtype = #{jobType} and recentmaketime like concat('%',#{month},'%') ")
    List<JobMake> selectByJobTypeAndRecentMakeTime(@Param("jobType") String jobType, @Param("month") String month);


    @Select("select id, type, year, month, day, hour, minute, second, state, pausetime, collect_frequency, dispname, collect_type " +
            "from collect_time where dispname =#{dispName} and collect_type = #{collectType}")
    List<CollectTime> selectCollectTime(@Param("dispName") String dispName, @Param("collectType") String collectType);


    @Select("select productname, producttype, producttime, publishtime, publissarea, publishstatus, publisher " +
            "from publish_record")
    List<PublishRecord> selectPublicRecord();

    @Update("update collect_time set state = #{state} where type = #{type}")
    Integer updateStateByType(@Param("type") String type, @Param("state") String state);

    @Select("<script>" +
            "select jobname,jobtype,recentmaketime " +
            "from job_make " +
            "where 1=1" +
            "<if test='nameType!=null'> and nametype like concat('%',#{nameType},'%')</if> " +
            "<if test='jobName!=null'>and jobname like concat('%',jobname,'%')</if>" +
            "</script>")
    List<JobMake> selectByJobTypeAndJobName(@Param("nameType") String nameType, @Param("jobName") String jobName);

    @Select("<script>" +
            "select id, productname, producttype, producttime, publishtime, publissarea, publishstatus, publisher " +
            "from publish_record" +
            " where 1=1" +
            "<if test='productName!=null'> and productname like concat('%',#{productName})</if> " +
            "<if test='productType!=null'> and producttype like concat('%',#{productType})</if>" +
            "</script>")
    List<PublishRecord> selectByProduceNameAndProductType(@Param("productName") String productName, @Param("productType") String productType);

    @Select("select jobname from job_make where nametype = #{nameType}")
    List<JobMake> selectJobName(String nameType);

}
